// const Koa = require('koa')
import Koa from 'Koa'
import KoaRouter from 'koa-router'
const app = new Koa()
const router = new KoaRouter()
import { setCorsHeader } from './set-cors.js'
import { getFileApi } from './file-upload.js'

router
  .get('/cors', async (ctx, next) => {
    setCorsHeader(ctx)
    ctx.body = {
      code: 1,
      message: 'success',
      result: null,
    }
    ctx.status = 200
  })
  .options('/cors', (ctx) => {
    setCorsHeader(ctx)
    console.log('options')
    ctx.body = {
      code: 1,
      message: 'success',
      result: null,
    }
    ctx.status = 200
  })

app.use(router.routes()).use(router.allowedMethods())
getFileApi(router, app)
app.listen(3000)
